package durst.data.dao.impl;

import java.sql.SQLException;
import java.util.List;

import com.j256.ormlite.dao.BaseDaoImpl;
import com.j256.ormlite.support.ConnectionSource;
import com.j256.ormlite.table.DatabaseTableConfig;

import durst.data.Account;
import durst.data.CSDMessage;

public class MessageDao<T, ID> extends BaseDaoImpl<T, ID> {
	@SuppressWarnings("unchecked")
	public MessageDao(ConnectionSource connectionSource)
			throws SQLException {
		super(connectionSource, (Class<T>)CSDMessage.class);
	}
	
	public MessageDao(ConnectionSource connectionSource,
			DatabaseTableConfig<T> tableConfig) throws SQLException {
		super(connectionSource, tableConfig);
	}

	public List<T> getRecievedMessages(Account acc) throws SQLException { 
		return queryBuilder().where().eq(CSDMessage.TARGET_ID, acc.getId()).query();
	}
	
	public List<T> getSentMessages(Account acc) throws SQLException {
		return queryBuilder().where().eq(CSDMessage.SENDER_ID, acc.getId()).query();
	}
}
